n,m = list(map(int, input().split()))
g = [[] for x in range(n)]

for i in range(m):
   f,t,w = list(map(int, input().split()))
   f,t = f-1,t-1
   g[f].append([t,w])
   g[t].append([f,w])
   
s,f = list(map(int, input().split()))
s,f = s-1,f-1

d = [10**20 for x in range(n)]
cc = [0 for x in range(n)]
u = [False for x in range(n)]

d[s] = 0
cc[s] = 1

for i in range(n):
   v = -1
   for j in range(n):
      if (not u[j]) and ((v == -1) or (d[j] < d[v])):
         v = j
   if d[v] == 10**20:
      break
   u[v] = True
   
   for j in range(len(g[v])):
      to = g[v][j][0]
      le = g[v][j][1]
      
      if (d[v] + le == d[to]):
         cc[to] += cc[v]
      if (d[v] + le < d[to]):
         d[to] = d[v] + le
         cc[to] = cc[v]

print(cc[f])
